package service;

import java.util.ArrayList;
import java.util.List;

public class BinaryStream {
    public static List<Byte> lock( String key, List<Byte> fileStream) {
        List<Byte> returnFileStream = new ArrayList<> ();
        byte[] keycode = key.getBytes ();
        int keycodeIndex = 0;
        for(int i = 0 ;i < fileStream.size ();i++) {
            returnFileStream.set ( i , (byte) ( fileStream.get ( i ) ^ keycode[keycodeIndex] ) );
            keycodeIndex++;
            if(keycodeIndex > keycode.length-1) {
                keycodeIndex = 0;
            }
        }
        return returnFileStream;
    }
}


